﻿--#include "data\config\recharge\FashionRechargeConfig.lua" once

function SendFashionRechargeGetState(sysarg)
	local sVar = Actor.getStaticVar(sysarg)
	local netPack = DataPack.allocPacket(sysarg, LogicCmd.miscSys.sysId, LogicCmd.miscSys.sub.sSendFashionRechargeData) 
	if not netPack then return end
	DataPack.writeInt(netPack, sVar.fashionRechargeYuanBao or 0)
	DataPack.writeByte(netPack, sVar.fashionRechargeState or 0)
	DataPack.flush(netPack)
end
function OnFashionRechargeLogin(sysarg)
	SendFashionRechargeGetState(sysarg)
end

function OnFashionRechargeWithDrawYuanBao(sysarg, nYuanBao)
	local sVar = Actor.getStaticVar(sysarg)
	sVar.fashionRechargeYuanBao = (sVar.fashionRechargeYuanBao or 0) + nYuanBao
	SendFashionRechargeGetState(sysarg)
end

function GetFashionRechargeAward(sysarg)
	local sVar = Actor.getStaticVar(sysarg)
	if not sVar.fashionRechargeState and (sVar.fashionRechargeYuanBao or 0) >= FashionRechargeConfig.yb then
		if CheckBagGridForAwardsEx(sysarg, FashionRechargeConfig.awards) == 0 then
			sVar.fashionRechargeState = 1
			GiveCommonAwardEx(sysarg, FashionRechargeConfig.awards, LogIds.FashionRechargeLogId, Lang.LogTips.FashionRecharge)
			SendFashionRechargeGetState(sysarg)
			local msg = string.format(Lang.ScriptTips.FashionRecharge001, Actor.getName(sysarg))
			System.broadcastTipmsgLimitLev(msg, ttScreenCenter + ttChatWindow)
		else
			Actor.sendTipmsg(sysarg, Lang.ScriptTips.COM0015, ttFlyTip)
		end
	end
end

